document.getElementById('members-list').addEventListener('click', event => {
    if (event.target && event.target.classList.contains('remove-user-btn')) {
        const userId = event.target.getAttribute('data-user-id');
        const roomId = document.getElementById('members-list').getAttribute('data-room-id');

        const data = new FormData();
        data.append('user_id', userId);
        data.append('room_id', roomId);

        fetch(`/chat/${userId}/${roomId}/block/`, {
            method: 'POST',
            headers: {
                'X-CSRFToken': '{{ csrf_token|escapejs }}'
            },
            body: data
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                alert(data.message);
                event.target.closest('.member-item').remove();
            } else {
                alert(data.error);
            }
        })
        .catch(err => {
            alert('操作失败');
            console.error(err);
        });
    }
});
// </script>
// <!--<script src="{% static 'js/members.js' %}">-->
// <!--  const csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value;-->
// <!--</script>-->